package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "套餐相关接口")
@RestController(value = "adminSetmealController")
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO dto) {
        PageResult pageResult = setmealService.page(dto);
        return Result.success(pageResult);
    }

    // @Cacheable(cacheNames = "setmealCache",key = "#id")
    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result getSetmealById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealService.getSetmealById(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("套餐起售、停售")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id) {
        setmealService.updateStatus(status,id);
        return Result.success();
    }

    @ApiOperation("新增套餐")
    @PostMapping
    public Result insert(@RequestBody SetmealVO dto) {
        setmealService.insert(dto);
        return Result.success();
    }

    @ApiOperation("批量删除")
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids) {
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO dto) {
        setmealService.update(dto);
        return Result.success();
    }

}
























